package com.sojson.util.mail.interfaces.impl;

import com.sojson.util.SpringUtil;
import com.sojson.util.mail.interfaces.MailUtilInterface;

/**
 * 发送邮件工具类实现类
 *
 * @author liu
 * @Date 2020-06-28 15:26:37
 * @Description
 *
 */
public class MailUtilImpl implements MailUtilInterface {

    private static MailUtilImpl mailUtilsImpl;
    private final MailSends sends = SpringUtil.getBeanByType(MailSends.class);

    private MailUtilImpl() {}

    /**
     * 发送一封邮件
     *
     * @param target    目标邮箱
     * @param title     邮件标题
     * @param content   邮件内容
     * @throws Exception
     */
    @Override
    public void send(String target, String title, String content) throws Exception {
        sends.run(target, title, content);
    }

    /**
     * 发送多封邮件
     *
     * @param targets   目标邮箱
     * @param title     邮件标题
     * @param content   邮件内容
     * @throws Exception
     */
    @Override
    public void send(String[] targets, String title, String content) throws Exception {
        sends.run(targets, title, content);
    }

    /**
     * 判断一个对象是否是空(空对象)
     *
     * @param obj
     * @return
     */
    private static boolean isBlankObject(Object obj) {
        return obj == null;
    }

    public static MailUtilImpl getInstances() {
        if (isBlankObject(mailUtilsImpl)) {
            mailUtilsImpl = new MailUtilImpl();
        }
        return mailUtilsImpl;
    }

}